# 回合制对战游戏
# •创建角色：名字、性别、血量、装备               •战斗
# •创建房间：                                 •血量默认100
# •角色可加入房间                              •正常被攻击-10滴血
# •房间内的人可互打                            •有防弹衣-5滴血
# •房间上限2人                                •装备-防弹衣

class Role():
    def __init__(self,name,sex,equip=None,hp = 100):
        self.name = name
        self.sex = sex
        self.equip = equip
        self.hp = hp
        self.room = None
    def battle(self,other):
        if self != other:
            if self.room == other.room:
                if self.hp > 0 and other.hp > 0:
                    #print(f"{self.name}和{other.name}血量旺盛，可以battle")
                    reduce_hp = 5 if other.equip else  10
                    other.hp -= reduce_hp
                    print(f"{self.name}攻击{other.name} {reduce_hp}点血量\t{self.name}当前血量：{self.hp}\t{other.name}当前血量：{other.hp}")
                else:
                    print("其中一方已死亡，不能攻击")
                    exit()
            else:
                print("你们不在同一房间")
        else:
            print("不能攻击自己撒！")


class Room():
    def __init__(self,name):
        self.name = name
        self.mamber_list = []
    def add_mamber(self,role):
        if role.room == None:
            if len(self.mamber_list) < 2:
                self.mamber_list.append(role)
                role.room = self.name
                print(f"{role.name}成功进入{self.name}房间")
        else:
            print(f"{role.name}已经进入房间了")

role_dict = {}
room_dict = {}
while True:
    print(f"1、创建角色".center(20,"*"))
    print(f"2、创建房间".center(20, "*"))
    print(f"3、加入房间".center(20, "*"))
    print(f"4、进行战斗".center(20, "*"))
    print(f"5、 退出  ".center(22, "*"))
    option = input("请输入你的选择：")
    if option == "1":
        name,sex = input("请输入你要创建的名字和性别：").split()
        role_dict[name] = Role(name, sex)
        name_hp = input("请输入血量：")
        role_dict[name].hp = int(name_hp)
        print(f"{name}用户的血量为{role_dict[name].hp}")
        role_equip = input("请输入p穿戴防弹衣")
        if role_equip == "p":
            role_dict[name].equip = 1
    elif option == "2":
        room_name = input("请输入房间的名字：")
        room_dict[room_name] = Room(room_dict)
    elif option == "3":
        print(f"当前角色有{role_dict.keys()}，当前房间有{room_dict.keys()}")
        role_name,room_name = input("请输入要加入的角色和房间名：").split()
        room_dict[room_name].add_mamber(role_dict[role_name])
    elif option == "4":
        print(f"当前房间有{room_dict.keys()}")
        room_name = input("请输入房间的名字：")
        if len(room_dict[room_name].mamber_list) == 2:
            while True:
                room_dict[room_name].mamber_list[0].battle(room_dict[room_name].mamber_list[1])
                room_dict[room_name].mamber_list[1].battle(room_dict[room_name].mamber_list[0])
        else:
            print(f"{room_name}房间不足两人")
            continue
    elif option == "5":
        print("退出对战")
        break


